'''
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。易于人阅读和编写
天然的跟python 列表、字典 字典理念雷同

在线json格式化 https://www.json.cn/

其他开源json模块 性能较高
https://github.com/DaveGamble/cJSON
https://github.com/esnme/ultrajson
'''

import json

data = \
    {'students': [
        {'name': 'a', 'age': 30, 'hobs': ['music', 'python']},
        {'name': 'b', 'age': 11, 'hobs': ['eat', 'sleep']},
    ],
        'total': 2
    }

# dumps py对象->json字符串 loads json字符串->py对象

# json_string = json.dumps(data)
json_string = json.dumps(data, indent=4)
print(type(json_string), json_string)
py_obj = json.loads(json_string)
print(type(py_obj), py_obj)

import ujson

json_string = ujson.dumps(data, indent=4)
print(type(json_string), json_string)
py_obj = ujson.loads(json_string)
print(type(py_obj), py_obj)
